package com.appwoo.txtws.activity;

import android.app.AlertDialog.Builder;
import android.app.Dialog;
import android.app.ProgressDialog;
import android.content.Context;
import android.content.DialogInterface;
import android.content.DialogInterface.OnCancelListener;
import android.content.DialogInterface.OnClickListener;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.content.pm.PackageInfo;
import android.content.pm.PackageManager;
import android.content.pm.PackageManager.NameNotFoundException;
import android.content.res.Resources;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Bundle;
import android.os.Environment;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.LinearLayout;
import android.widget.ProgressBar;
import android.widget.TextView;
import android.widget.Toast;
import com.appwoo.txtws.app.AppActivity;
import com.appwoo.txtws.bean.StateBean;
import com.appwoo.txtws.component.Global;
import com.appwoo.txtws.component.Logger;
import com.appwoo.txtws.service.UpdateService;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.URL;
import java.net.URLConnection;
import java.util.Date;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
import org.apache.http.StatusLine;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.impl.client.DefaultHttpClient;
import org.xmlpull.v1.XmlPullParserException;

public class AboutActivity extends AppActivity
{
  private static final String APK_PACKAGE_NAME = "com.appwoo.txtws.activity";
  private static final int DIALOG1 = 0;
  private static final int DIALOG_DOWNLOAD = 3;
  private Button btnUpdate;
  private UpdateService f_updateService = null;
  private String f_url = "";
  private boolean isCancelDownload = false;
  private LinearLayout llEmail;
  private LinearLayout llMz;
  private LinearLayout llWeb;
  private LinearLayout ll_dial;
  private TextView myProssBarhandleText;
  private Button mz_btn = null;
  private ProgressBar progressBarHandle;
  private String strApkVersion = "";
  private TextView tvEmail;
  private TextView tvVersion;
  private TextView tvWeb;
  private TextView tv_Num;
  private String updateStr = "";
  private ProgressDialog v_progressDialog = null;

  private void addListener()
  {
    this.llMz.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        Intent localIntent = new Intent(AboutActivity.this, MSZMActivity.class);
        AboutActivity.this.startActivity(localIntent);
      }
    });
    this.ll_dial.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        AboutActivity.this.dialDialog();
      }
    });
    this.llWeb.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (AboutActivity.this.tvWeb != null)
        {
          String str = AboutActivity.this.tvWeb.getText().toString();
          Intent localIntent = new Intent();
          localIntent.setAction("android.intent.action.VIEW");
          localIntent.setData(Uri.parse(str));
          localIntent.setClassName("com.android.browser", "com.android.browser.BrowserActivity");
          AboutActivity.this.startActivity(localIntent);
        }
      }
    });
    this.llEmail.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        AboutActivity.this.sendMail(AboutActivity.this.tvEmail.getText().toString());
      }
    });
    this.btnUpdate.setOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        if (!AboutActivity.this.isNetworkAvailable(AboutActivity.this))
        {
          AboutActivity.this.alertMessage(AboutActivity.this.getString(2131428051));
          return;
        }
        AboutActivity.this.showView();
      }
    });
  }

  private String bg_checkUpdateVersion()
  {
    try
    {
      String str = getPackageManager().getPackageInfo(getPackageName(), 0).versionName;
      StateBean localStateBean = this.f_updateService.getUpdateUrl(str);
      this.f_url = localStateBean.getUrl();
      this.updateStr = localStateBean.getDesc();
      label46: return this.f_url;
    }
    catch (XmlPullParserException localXmlPullParserException)
    {
      break label46;
    }
    catch (IOException localIOException)
    {
      break label46;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      break label46;
    }
  }

  private String bg_download()
  {
    Boolean localBoolean = Boolean.valueOf(isSDCard());
    String str = Environment.getExternalStorageDirectory().getPath() + "/download_cache";
    File localFile1 = new File(str);
    if (!localFile1.exists())
      localFile1.mkdir();
    HttpGet localHttpGet = new HttpGet(this.f_url);
    try
    {
      HttpResponse localHttpResponse = new DefaultHttpClient().execute(localHttpGet);
      if (localHttpResponse.getStatusLine().getStatusCode() != 200)
        break label334;
      InputStream localInputStream = localHttpResponse.getEntity().getContent();
      FileOutputStream localFileOutputStream;
      byte[] arrayOfByte;
      if (localBoolean.booleanValue())
      {
        localFileOutputStream = new FileOutputStream(str + "/txtw.apk");
        arrayOfByte = new byte[8192];
      }
      while (true)
      {
        int i = localInputStream.read(arrayOfByte);
        if (i == -1)
        {
          localFileOutputStream.close();
          localInputStream.close();
          SharedPreferences.Editor localEditor = getSharedPreferences("sys", 0).edit();
          localEditor.putInt("isupload", 1);
          localEditor.commit();
          if (!localBoolean.booleanValue())
            break label286;
          installApk(str + "/txtw.apk");
          return "";
          localFileOutputStream = openFileOutput("txtw.apk", 1);
          break;
        }
        localFileOutputStream.write(arrayOfByte, 0, i);
      }
    }
    catch (Exception localException)
    {
      return getString(2131427557);
    }
    label286: File localFile2 = getFilesDir();
    installApk(localFile2.getParent() + File.separator + localFile2.getName() + "/txtw.apk");
    label334: return "";
  }

  private Dialog buildDialog(Context paramContext)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setIcon(2130837508);
    localBuilder.setTitle(getResources().getString(2131427429));
    localBuilder.setMessage(formString());
    localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        new AboutActivity.DownloadAsyncTask(AboutActivity.this).execute(new Void[] { null });
      }
    });
    localBuilder.setNegativeButton(getString(2131427512), null);
    localBuilder.setCancelable(false);
    return localBuilder.create();
  }

  private void createOrShowDialog()
  {
    if ((this.v_progressDialog == null) || (!this.v_progressDialog.isShowing()))
    {
      this.v_progressDialog = new ProgressDialog(this);
      this.v_progressDialog.setMessage(getString(2131427561));
      this.v_progressDialog.setCancelable(false);
      this.v_progressDialog.show();
    }
  }

  private void dialDialog()
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(this);
    localBuilder.create();
    localBuilder.setMessage(getString(2131427555) + this.tv_Num.getText() + "？");
    localBuilder.setPositiveButton(getString(2131427513), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        Intent localIntent = new Intent("android.intent.action.CALL", Uri.parse("tel:" + AboutActivity.this.tv_Num.getText()));
        AboutActivity.this.startActivity(localIntent);
      }
    }).setNegativeButton(getString(2131427514), null);
    localBuilder.show();
  }

  private Dialog downDialog(Context paramContext)
  {
    AlertDialog.Builder localBuilder = new AlertDialog.Builder(paramContext);
    localBuilder.setTitle(getString(2131427559));
    View localView = getLayoutInflater().inflate(2130903084, null);
    localBuilder.setView(localView);
    this.progressBarHandle = ((ProgressBar)localView.findViewById(2131493072));
    this.myProssBarhandleText = ((TextView)localView.findViewById(2131493073));
    localBuilder.setOnCancelListener(new DialogInterface.OnCancelListener()
    {
      public void onCancel(DialogInterface paramAnonymousDialogInterface)
      {
        AboutActivity.this.isCancelDownload = true;
      }
    });
    localBuilder.setNegativeButton(getString(2131427560), new DialogInterface.OnClickListener()
    {
      public void onClick(DialogInterface paramAnonymousDialogInterface, int paramAnonymousInt)
      {
        AboutActivity.this.isCancelDownload = true;
      }
    });
    return localBuilder.create();
  }

  private String formString()
  {
    Object localObject = "";
    try
    {
      localObject = localObject + getResources().getString(2131427438) + "\n";
      String[] arrayOfString = this.updateStr.split("#");
      for (int i = 0; ; i++)
      {
        if (i >= arrayOfString.length)
          return localObject;
        String str = localObject + (i + 1) + "、" + arrayOfString[i] + "\n";
        localObject = str;
      }
    }
    catch (NullPointerException localNullPointerException)
    {
      Logger.e("xjf", localNullPointerException.toString());
      return localObject;
    }
    catch (Exception localException)
    {
      Logger.e("xjf", localException.toString());
    }
    return localObject;
  }

  private String getApkVersion()
  {
    try
    {
      String str = getPackageManager().getPackageInfo("com.appwoo.txtws.activity", 0).versionName;
      return str;
    }
    catch (PackageManager.NameNotFoundException localNameNotFoundException)
    {
      localNameNotFoundException.printStackTrace();
    }
    return "";
  }

  private void initActionBar()
  {
    hideBarHome();
    setBarTitle(getResources().getString(2131427457));
    setBarBackOnClickListener(new View.OnClickListener()
    {
      public void onClick(View paramAnonymousView)
      {
        AboutActivity.this.finish();
      }
    });
  }

  private void initView()
  {
    this.llMz = ((LinearLayout)findViewById(2131492883));
    this.ll_dial = ((LinearLayout)findViewById(2131492877));
    this.tv_Num = ((TextView)findViewById(2131492878));
    this.llWeb = ((LinearLayout)findViewById(2131492881));
    this.tvWeb = ((TextView)findViewById(2131492882));
    this.llEmail = ((LinearLayout)findViewById(2131492879));
    this.tvEmail = ((TextView)findViewById(2131492880));
    this.tvVersion = ((TextView)findViewById(2131492875));
    this.btnUpdate = ((Button)findViewById(2131492876));
    this.f_updateService = new UpdateService();
    this.strApkVersion = getApkVersion();
    this.tvVersion.setText(this.strApkVersion);
  }

  private void installApk(String paramString)
  {
    File localFile = new File(paramString);
    Intent localIntent = new Intent();
    localIntent.addFlags(268435456);
    localIntent.setAction("android.intent.action.VIEW");
    localIntent.setDataAndType(Uri.fromFile(localFile), "application/vnd.android.package-archive");
    startActivity(localIntent);
  }

  private void post_checkUpdateVersion(String paramString)
  {
    if ((paramString == null) || ("".equals(paramString)))
    {
      alertMessage(getString(2131427558));
      return;
    }
    if (!isSDCard())
    {
      if (Global.getMemorySize() >= 30)
      {
        showDialog(0);
        return;
      }
      alertMessage(getString(2131427337));
      return;
    }
    showDialog(0);
  }

  private void post_download(String paramString)
  {
    if ((paramString != null) && (!"".equals(paramString)))
      alertMessage(paramString);
  }

  private void showView()
  {
    new Flash_AsyncTask().execute(new String[] { "check" });
  }

  protected void backKeyCallBack()
  {
    finish();
  }

  public boolean isSDCard()
  {
    try
    {
      long l = new Date().getTime();
      File localFile = new File("/sdcard/" + l + ".test");
      boolean bool = localFile.createNewFile();
      localFile.delete();
      Logger.i("xjf", "sdcard can use");
      return bool;
    }
    catch (Exception localException)
    {
      localException.printStackTrace();
      Logger.i("xjf", "No SDCard!!");
    }
    return false;
  }

  public void onBackPressed()
  {
    finish();
  }

  public void onCreate(Bundle paramBundle)
  {
    super.onCreate(paramBundle);
    setContentView(2130903041);
    initActionBar();
    initView();
    addListener();
    isSDCard();
  }

  protected Dialog onCreateDialog(int paramInt)
  {
    switch (paramInt)
    {
    case 1:
    case 2:
    default:
      return null;
    case 0:
      return buildDialog(this);
    case 3:
    }
    return downDialog(this);
  }

  public void sendMail(String paramString)
  {
    try
    {
      Intent localIntent = new Intent();
      localIntent.setType("message/rfc822");
      localIntent.setAction("android.intent.action.SEND");
      localIntent.putExtra("android.intent.extra.EMAIL", new String[] { paramString });
      startActivity(Intent.createChooser(localIntent, "Sending  mail..."));
      return;
    }
    catch (Exception localException)
    {
      logError("Send Error:", localException);
    }
  }

  class DownloadAsyncTask extends AsyncTask<Void, Integer, Integer>
  {
    private final String downPath = Environment.getExternalStorageDirectory().getPath() + "/download_cache";
    private int fileSize;
    private String filename;
    private FileOutputStream fos;
    private InputStream is;

    DownloadAsyncTask()
    {
    }

    protected Integer doInBackground(Void[] paramArrayOfVoid)
    {
      this.filename = AboutActivity.this.f_url.substring(1 + AboutActivity.this.f_url.lastIndexOf("/"));
      try
      {
        URL localURL = new URL(AboutActivity.this.f_url);
        Logger.e("xjf", "downpath: " + this.downPath);
        URLConnection localURLConnection = localURL.openConnection();
        localURLConnection.connect();
        this.is = localURLConnection.getInputStream();
        this.fileSize = localURLConnection.getContentLength();
        AboutActivity.this.progressBarHandle.setMax(this.fileSize);
        if (this.fileSize <= 0)
          throw new RuntimeException(AboutActivity.this.getString(2131427562));
      }
      catch (Exception localException)
      {
        localException.printStackTrace();
        Logger.d("xjf", localException.getMessage());
        return Integer.valueOf(this.fileSize);
        if (this.is == null)
          throw new RuntimeException("stream is null");
      }
      finally
      {
        AboutActivity.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
      }
      label272: byte[] arrayOfByte;
      int i;
      label306: int j;
      if (AboutActivity.this.isSDCard())
      {
        this.fos = new FileOutputStream(this.downPath + "/" + this.filename);
        arrayOfByte = new byte[1024];
        i = 0;
        Logger.d("xjf", "fileSize:" + this.fileSize);
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(0);
        j = this.is.read(arrayOfByte);
        if (j != -1)
          break label367;
      }
      while (true)
      {
        AboutActivity.this.isCancelDownload = false;
        com.appwoo.txtws.service.WebTimeControlService.isWho = Integer.valueOf(1);
        break;
        this.fos = AboutActivity.this.openFileOutput(this.filename, 1);
        break label272;
        label367: this.fos.write(arrayOfByte, 0, j);
        i += j;
        Integer[] arrayOfInteger = new Integer[1];
        arrayOfInteger[0] = Integer.valueOf(i);
        publishProgress(arrayOfInteger);
        if (AboutActivity.this.isCancelDownload)
          this.fileSize = -1;
        boolean bool = AboutActivity.this.isCancelDownload;
        if (!bool)
          break label306;
      }
    }

    protected void onPostExecute(Integer paramInteger)
    {
      if (paramInteger.intValue() != -1)
        Toast.makeText(AboutActivity.this, AboutActivity.this.getString(2131427563) + Math.round(100.0F * paramInteger.intValue() / 1048576.0F) / 100.0F + "MB", 1).show();
      try
      {
        while (true)
        {
          AboutActivity.this.dismissDialog(3);
          try
          {
            label75: Boolean localBoolean = Boolean.valueOf(AboutActivity.this.isSDCard());
            if (paramInteger.intValue() != -1)
            {
              if (!localBoolean.booleanValue())
                break label189;
              if (paramInteger.intValue() != -1)
                AboutActivity.this.installApk(this.downPath + "/" + this.filename);
            }
            while (true)
            {
              if (this.is != null)
                this.is.close();
              if (this.fos != null)
                this.fos.close();
              return;
              this.fos = null;
              this.is = null;
              break;
              label189: File localFile = AboutActivity.this.getFilesDir();
              if (paramInteger.intValue() != -1)
                AboutActivity.this.installApk(localFile.getParent() + File.separator + localFile.getName() + "/" + this.filename);
            }
          }
          catch (Exception localException2)
          {
            Logger.e("xjf", "error: " + localException2.getMessage(), localException2);
            return;
          }
        }
      }
      catch (Exception localException1)
      {
        break label75;
      }
    }

    protected void onPreExecute()
    {
      File localFile = new File(this.downPath);
      if (!localFile.exists())
        localFile.mkdir();
      AboutActivity.this.showDialog(3);
    }

    protected void onProgressUpdate(Integer[] paramArrayOfInteger)
    {
      AboutActivity.this.progressBarHandle.setProgress(paramArrayOfInteger[0].intValue());
      int i = (int)(100.0F * (AboutActivity.this.progressBarHandle.getProgress() / AboutActivity.this.progressBarHandle.getMax()));
      AboutActivity.this.myProssBarhandleText.setText(i + "%");
    }
  }

  public class Flash_AsyncTask extends AsyncTask<String, Integer, String>
  {
    private String method = "";

    public Flash_AsyncTask()
    {
    }

    protected String doInBackground(String[] paramArrayOfString)
    {
      this.method = paramArrayOfString[0];
      if (this.method.equals("check"))
        return AboutActivity.this.bg_checkUpdateVersion();
      if (this.method.equals("download"))
        return AboutActivity.this.bg_download();
      return "";
    }

    protected void onPostExecute(String paramString)
    {
      if (this.method.equals("check"))
        AboutActivity.this.post_checkUpdateVersion(paramString);
      while (true)
      {
        AboutActivity.this.v_progressDialog.dismiss();
        return;
        if (this.method.equals("download"))
          AboutActivity.this.post_download(paramString);
      }
    }

    protected void onPreExecute()
    {
      AboutActivity.this.createOrShowDialog();
    }
  }
}

/* Location:           C:\Documents and Settings\Administrator\classes_dex2jar.jar
 * Qualified Name:     com.appwoo.txtws.activity.AboutActivity
 * JD-Core Version:    0.6.2
 */